package com.prs.crm.view;

import javax.servlet.ServletContext;

import org.apache.struts2.StrutsConstants;
import org.apache.struts2.views.freemarker.FreemarkerManager;

import com.opensymphony.xwork2.inject.Inject;

import freemarker.template.TemplateException;
import freemarker.template.TemplateExceptionHandler;

public class MyFreemarkerManager extends FreemarkerManager{
	 private String encoding;
	    
	    @Inject(StrutsConstants.STRUTS_I18N_ENCODING)
	    public void setEncoding(String encoding) {
	        this.encoding = encoding;
	    }
	    
	    @Override
	    protected freemarker.template.Configuration createConfiguration(ServletContext servletContext) throws TemplateException {

	        freemarker.template.Configuration configuration = new freemarker.template.Configuration();

	        configuration.setTemplateLoader(getTemplateLoader(servletContext));

	        configuration.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);

	        configuration.setObjectWrapper(getObjectWrapper());
	        
	        if( mruMaxStrongSize > 0 ) {
	            configuration.setSetting(freemarker.template.Configuration.CACHE_STORAGE_KEY, "strong:" + mruMaxStrongSize);
	        }
	        configuration.addAutoImport("prs", "/module/ui.ftl");
	        if (encoding != null) {
	            configuration.setDefaultEncoding(encoding);
	        }

	        loadSettings(servletContext, configuration);

	        return configuration;
	    }


	}